﻿package engine.gui 
{
	import flash.display.Shape;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.text.*;
	import flash.events.MouseEvent;
	import flash.events.Event;
	import it.gotoandplay.smartfoxserver.SmartFoxClient;

	
	/**
	 * ...
	 * @author Jon Smelquist
	 */
	public class LoginScreen extends Sprite
	{
		
		protected var _nickname:TextField;
		protected var _password:TextField;
		protected var _login:SimpleButton;
		protected var _sfClient:SmartFoxClient;
		
		public function LoginScreen(sfClient:SmartFoxClient) 
		{
			var background:Shape = new Shape();
			background.graphics.beginFill(0xFFFFFF);
			background.graphics.drawRect( 0, 0, 640, 480);
			addChild(background);
			
			_login = new SimpleButton();
			_login.addEventListener(MouseEvent.CLICK, onClickHandler);


			addChild(_login);
			
			
			_sfClient = sfClient;

			makeNickname();
			makePassword();
			makeButton();
		}
		
		private function makeButton():void 
		{
			_login = new SimpleButton();
			_login.addEventListener(MouseEvent.CLICK, onClickHandler);
			_login.x = 250;
			_login.y = 160;
			
			var down:Sprite = new Sprite();
			down.graphics.lineStyle(1, 0x000000);
			down.graphics.beginFill(0xFFCC00);
			down.graphics.drawRect(10, 10, 100, 30);

			
			var up:Sprite = new Sprite();
			up.graphics.lineStyle(1, 0x000000);
			up.graphics.beginFill(0x0099FF);
			up.graphics.drawRect(10, 10, 100, 30);

			var over:Sprite = new Sprite();
			over.graphics.lineStyle(1, 0x000000);
			over.graphics.beginFill(0x9966FF);
			over.graphics.drawRect(10, 10, 100, 30);

			_login.upState = up;
			_login.overState = over;
			_login.downState = down;
			_login.useHandCursor = true;
			_login.hitTestState = up;

			addChild(_login);
		}
		
		private function makeNickname():void 
		{
			_nickname = new TextField();
			_nickname.border = true;
			_nickname.height = 20;
			_nickname.width = 300;
			_nickname.y = 100;
			_nickname.x = 170;
			_nickname.text = "Nickname";
			_nickname.defaultTextFormat.align = TextFormatAlign.CENTER;
			_nickname.type = TextFieldType.INPUT;
			addChild(_nickname);
		}
		private function makePassword():void 
		{
			_password = new TextField();
			_password.border = true;
			_password.height = 20;
			_password.width = 300;
			_password.y = 130;
			_password.x = 170;
			_password.text = "";
			_password.displayAsPassword = true;
			_password.defaultTextFormat.align = TextFormatAlign.CENTER;
			_password.type = TextFieldType.INPUT;
			addChild(_password);
		}
		
		private function onClickHandler(evt:Event):void
		{
			_sfClient.login("nothing", _nickname.text, _nickname.text);
		}
		
	}
	
}